Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release-22.2: opt: correctly track UDTs and UDFs for query cache invalidation #100223

Merged

Conversation

DrewKimball
Copy link
Collaborator

@DrewKimball DrewKimball commented Mar 30, 2023

Backport:

Please see individual PRs for details.

/cc @cockroachdb/release

Release Justification: low-risk bug fix for rare incorrect results for UDTs and UDFs

This commit performs some refactoring for the way data source objects
are tracked in `opt.Metadata` in order to make future changes to UDT
and UDF dependency tracking easier. More particularly, UDTs and UDFs
will be able to re-resolve any references by name. This is necessary
in order to handle cases where changes to the search-path cause names
in the query to resolve to different objects.

Release note: None
Previously, it was possible for invalid queries to be kept in the cache
after a schema change, since user-defined types were tracked only by OID.
This missed cases where the search path changed which object a name in
the query resolved to (or whether it resolved at all).

This patch fixes this behavior by tracking UDT references by name, similar
to what was already done for data sources. This ensures that the query
staleness check doesn't miss changes to the search path.

Fixes cockroachdb#96674

Release note (bug fix): Fixed a bug that could prevent a cached query with
a user-defined type reference from being invalidated even after a schema
change that should prevent the type from being resolved.
@DrewKimball DrewKimball requested a review from a team March 30, 2023 22:37
@DrewKimball DrewKimball requested review from a team as code owners March 30, 2023 22:37
@blathers-crl
Copy link

blathers-crl bot commented Mar 30, 2023

Thanks for opening a backport.

Please check the backport criteria before merging:

  • Patches should only be created for serious issues or test-only changes.
  • Patches should not break backwards-compatibility.
  • Patches should change as little code as possible.
  • Patches should not change on-disk formats or node communication protocols.
  • Patches should not add new functionality.
  • Patches must not add, edit, or otherwise modify cluster versions; or add version gates.
If some of the basic criteria cannot be satisfied, ensure that the exceptional criteria are satisfied within.
  • There is a high priority need for the functionality that cannot wait until the next release and is difficult to address in another way.
  • The new functionality is additive-only and only runs for clusters which have specifically “opted in” to it (e.g. by a cluster setting).
  • New code is protected by a conditional check that is trivial to verify and ensures that it only runs for opt-in clusters.
  • The PM and TL on the team that owns the changed code have signed off that the change obeys the above rules.

Add a brief release justification to the body of your PR to justify this backport.

Some other things to consider:

  • What did we do to ensure that a user that doesn’t know & care about this backport, has no idea that it happened?
  • Will this work in a cluster of mixed patch versions? Did we test that?
  • If a user upgrades a patch version, uses this feature, and then downgrades, what happens?

@DrewKimball DrewKimball removed request for a team March 30, 2023 22:37
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Collaborator

@mgartner mgartner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 4 of 4 files at r1, 5 of 5 files at r2, 10 of 10 files at r3, 3 of 3 files at r4, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @michae2)

This patch adds tracking for user-defined functions in `opt.Metadata`.
This ensures that the query cache will be correctly invalidated after
a schema change or search-path change that could change the query's
semantics, or cause it to error.

Fixes cockroachdb#93082
Fixes cockroachdb#93321

Release note (bug fix): Fixed a bug that could prevent a cached query
from being invalidated when a UDF referenced by that query was altered
or dropped.
It is possible to define a user-defined function with the same signature
as a builtin function. Normally, an unqualified function call will resolve
to the builtin function because its schema will be first in the search path.
However, it is possible to modify the search path, so that the same function
call can resolve to different functions on different executions. Example:
```
CREATE FUNCTION public.abs(val INT) RETURNS INT CALLED ON NULL INPUT LANGUAGE SQL AS $$ SELECT val+100 $$;
SELECT abs(1); --This should resolve to the builtin abs().
SET search_path = public, pg_catalog;
SELECT abs(1); --This should resolve to the udf abs().
```

Fixes cockroachdb#97757

Release note (bug fix): Fixed a bug existing from when user-defined
functions were introduced that could cause a function call to resolve
to the wrong function after changes to the schema search path.
@DrewKimball
Copy link
Collaborator Author

TFTR!

@DrewKimball DrewKimball merged commit e2bd618 into cockroachdb:release-22.2 Apr 3, 2023
@DrewKimball DrewKimball deleted the backport22.2-96045-99503 branch April 3, 2023 21:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants